package cn.xm.canting.bean;

import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.ArrayList;
import java.util.List;

public class AllFood extends LitePalSupport {
    private int id;
    private String foodName;
    private String foodContent;
    private int foodPrice;
    private int imgId;
    private int num;

    @Override
    public String toString() {

        return "AllFood{" +
                "id=" + id +
                ", foodName='" + foodName + '\'' +
                ", foodContent='" + foodContent + '\'' +
                ", foodPrice=" + foodPrice +
                ", imgId=" + imgId +
                ", num=" + num +
                '}';

    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getImgId() {
        return imgId;
    }

    public void setImgId(int imgId) {
        this.imgId = imgId;
    }

    public AllFood(String foodName, String foodContent, int foodPrice, int imgId) {

        this.foodName = foodName;
        this.foodContent = foodContent;
        this.foodPrice = foodPrice;
        this.imgId = imgId;
    }
    public AllFood(){
        super();
    }
    //添加至数据库的方法,传一个List.
    public static void addDB(List<AllFood> foods) {
        //查询表中是否有该餐品,如果有,则不进行添加,如果没有则添加
        foods = new ArrayList<>();
        for (int i = 0; i < foods.size(); i++) {
            foods = LitePal.where("foodName = ?", foods.get(i).foodName).find(AllFood.class);
            if (foods.size() == 0) {
                AllFood food = new AllFood(foods.get(i).foodName,foods.get(i).foodContent,foods.get(i).foodPrice,foods.get(i).imgId);
                food.save();
            }
        }
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }


    public String getFoodName() {
        return foodName;
    }

    public void setFoodName(String foodName) {
        this.foodName = foodName;
    }

    public String getFoodContent() {
        return foodContent;
    }

    public void setFoodContent(String foodContent) {
        this.foodContent = foodContent;
    }

    public int getFoodPrice() {
        return foodPrice;
    }

    public void setFoodPrice(int foodPrice) {
        this.foodPrice = foodPrice;
    }

}
